
module.exports = {
	getWxNews: async function() {
		return new Promise(func => {
			let _location = encodeURIComponent(window.location.href)
		console.log(_location,'666888window.location.href666999',window.location.href)
			// var href = 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=' + 'wxad6693c63cdd7ff6' + //data.appId + //wx53cfa21a6fb37682
			// 	'&redirect_uri=' + _location +
			// 	'&response_type=code&scope=snsapi_userinfo&state=wechat' + //data.state +
			// 	'#wechat_redirec'
			// window.location.href = href;
		})
	},
	getUrlParam:function(name){
			let reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
			let r = window.location.search.substr(1).match(reg);
			if (r != null) {
				return unescape(r[2]);
			}
			return null;
		},
	aaa:function(){
			 console.log('代码来源：https://blog.csdn.net/ltns_li/article/details/108850313')
		// if (isWechat()) {
			let code = getUrlParam("code"); //是否存在code 截取code代码 授权会返回code需要截取链接中code
			let local = window.location.href;
			if (code == null || code === "") {
				//不存在就打开上面的地址进行授权
				window.location.href =
					`https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxad6693c63cdd7ff6&redirect_uri=local&response_type=code&scope=snsapi_userinfo&state=STATE&connect_redirect=1#wechat_redirect`;
				console.log(111111111111111)
			//appid填写你的appid 	redirect_uri填写请求成功后回调地址						
			} else {
				that.code = code;
				//把code传给后端判断用户是否关注相对应的公众号
				console.log(222222222222222222222222)
				
				
				
				
				
				
				// uni.request({
				// 	url: 'url',
				// 	header: {
				// 		'content-type': 'application/x-www-form-urlencoded'
				// 	},
				// 	data: {
				// 		code: that.code
				// 	},
				// 	method: 'GET',
				// 	success: (res) => {
				// 		//201没有关注公众号 跳转关注页面
				// 		if (res.data == 201) {
				// 			window.location.href =
				// 				`https://mp.weixin.qq.com/mp/profile_ext?action=home&__biz=wechatbiz#wechat_redirect`;
				// 			//_biz的获取通过登录微信公众平台 在头像那里右击查看源码 找到 uin: "658565",uin_base64: ""，_biz的值等于uin_base64就可以了
				// 		} else { //关注了可以进行下一步
				// 			uni.request({
				// 				url: 'url',
				// 				header: {
				// 					'content-type': 'application/x-www-form-urlencoded'
				// 				},
				// 				method: 'GET',
				// 				success: (ti) => {
								
				// 				}
				// 			})
				// 		}
				// 	},
				// })
			}
		// }else{
		// 	uni.showModal({
		// 		title:'请在微信打开',
		// 		content:'请在微信打开本网页'
		// 	})
		// }
	},
	showMsg: function(title, duration=1500, mask=false, icon='none') {
		//统一提示方便全局修改
		if(Boolean(title) === false){
			return;
		}
		uni.showToast({
			title,
			duration,
			mask,
			icon
		});
	},
	prePage: function() {
		
		let pages = getCurrentPages();
		let prePage = pages[pages.length - 2];
		console.log("prePage: prePage");
		// #ifdef H5
		return prePage;
		// #endif
		return prePage.$vm;
	},
	putExtra: function(obj){
		return encodeURIComponent(JSON.stringify(obj));
	},
	
	getExtra: function(obj){
		return JSON.parse(decodeURIComponent(obj));
	}
}

